package com.superman.supermarket.client.composite.home.top;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.supermarket.client.gin.ShopGinjector;
import com.superman.supermarket.client.widget.button.CartButton;
import com.superman.supermarket.client.widget.button.CategoriesButton;
import com.superman.supermarket.client.widget.button.MyHeaderButton;
import com.superman.supermarket.client.widget.search.SearchBox;

/**
 * 首页头部模块-包含搜索和购物车等按钮
 * 
 * @author superman
 * @version 2018年7月20日下午9:43:22
 */
public class HomeTopModule extends FlowPanel {

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年7月20日 下午9:43:24
	 */
	public HomeTopModule() {
		this.setSize("9.6rem", "1.2rem");
		this.getElement().addClassName("flex-h flex-vc flex-hs");
		this.getElement().getStyle().setProperty("padding", "0 0.2rem");
		this.getElement().getStyle().setProperty("background", "#fff");

		this.add(new CategoriesButton());
		this.add(initSearchBox());
		this.add(initUserHeaderImg());
		this.add(initCartIcon());
	}

	private Widget initCartIcon() {
		CartButton cartButton = new CartButton();
		cartButton.getElement().getStyle().setProperty("marginLeft", "0.266667rem");
		return cartButton;
	}

	private SearchBox initSearchBox() {
		SearchBox searchBox = new SearchBox();
		searchBox.setPlaceHolder("在这里搜索你想要的商品");
		searchBox.setReadOnly(true);
		searchBox.getElement().getStyle().setProperty("marginLeft", "0.1333333rem");
		searchBox.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				XGinjector.INSTANCE.getMyPlaceController().push(ShopGinjector.INSTANCE.getMyPlaceFactory().getGoodsSearchPlace());
			}
		});
		return searchBox;
	}

	private Widget initUserHeaderImg() {
		MyHeaderButton myHeaderButton = new MyHeaderButton();
		myHeaderButton.getElement().getStyle().setProperty("marginLeft", "0.266667rem");
		return myHeaderButton;
	}

}
